package com;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {
	/*
	 * public static String md5(String str) throws NoSuchAlgorithmException {
	 * MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] srcBytes =
	 * str.getBytes(StandardCharsets.UTF_8); md5.update(srcBytes); byte[]
	 * resultBytes = md5.digest(); return new String(resultBytes); }
	 */
    
    public static String md5(String str) {
		String hashedPwd = "";
	    try {
	        MessageDigest md = MessageDigest.getInstance("MD5");// 生成一个MD5加密计算摘要
	        md.update(str.getBytes());// 计算md5函数
	        hashedPwd = new BigInteger(1, md.digest()).toString(16);// 16是表示转换为16进制数
//	        System.out.println(hashedPwd); 
	    } catch (NoSuchAlgorithmException e) {
	        e.printStackTrace();
	    }
	    return hashedPwd;
	    
	}
    
}

